package cn.hn.tx.rebot.task.job;

import java.util.Iterator;
import java.util.List;

import cn.hn.comm.Tools;
import cn.hn.net.Kit;
import cn.hn.tx.rebot.blog.model.Blog;
import cn.hn.tx.rebot.task.model.TaskExeLog;

/**
 * 刷新在线用户数量
 * @author shenhao
 *
 */
public class Task_UpdateOnlineUsers extends ITaskJob {
	
	//用户数
	private int user_num;
	//在线时长——单位分钟
	private int online_time;
	//用户在线列表地址
	private String url_randonline;
	
	
	@Override
	void executeJob() {
		System.out.println("开始:"+getTaskName());
		// 任务执行记录日志
		TaskExeLog taskExeLog = new TaskExeLog();
		taskExeLog.setStartTime(Tools.getCurDate(null));
		taskExeLog.setTaskName(this.getTaskName());
		taskExeLog.setType(type().getType());
		String taskLogMemo;

		try {
			String params="cp=rand&minid=1&maxid=300&total="+user_num+"&onlinetime="+online_time;
			String request_url=url_randonline+"?"+params;
			Kit.httpRequest(request_url, null, "GET", "GBK");
			
			
			taskLogMemo="刷新在线用户成功";
		} catch (Exception e) {
			//记录异常
			getExceptionService().insertException(this.getClass().getName(), "executeJob()", e.toString());
			taskLogMemo="任务执行失败.原因:"+e.toString();
		}
		taskExeLog.setMemo(taskLogMemo);
		taskExeLog.setEndTime(Tools.getCurDate(null));
		//记录任务执行日志
		getTaskService().insertTaskExeLog(taskExeLog);
		System.out.println("结束:"+getTaskName());

	}

	@Override
	public
	TaskType type() {
		// TODO Auto-generated method stub
		return TaskType.UpdateOnlineUsers;
	}

	public int getUser_num() {
		return user_num;
	}

	public void setUser_num(int user_num) {
		this.user_num = user_num;
	}

	public int getOnline_time() {
		return online_time;
	}

	public void setOnline_time(int online_time) {
		this.online_time = online_time;
	}

	public String getUrl_randonline() {
		return url_randonline;
	}

	public void setUrl_randonline(String url_randonline) {
		this.url_randonline = url_randonline;
	}

}
